package com.infraassets.models
{
	import mx.collections.ArrayCollection;
	
	[Bindable]
	public class CodingModel
	{
		public var codingList:ArrayCollection;
		public var categoryList:ArrayCollection;
		public var groupList:ArrayCollection;
		public var descriptorList:ArrayCollection;
		public var modifierList:ArrayCollection;
		public var modifierDetailList:ArrayCollection;
		public var continousDefectTypeList:ArrayCollection;
		public var scoreList:ArrayCollection;
		public var pipeCategoryId:int;
		public var uploadURL:String;
		public var score1:String;
		public var score2:String;
		public var condition1:String;
		public var condition2:String;
		public var isLarge:Boolean;
		public var isMedium:Boolean;
		public var wallThickness:int;
		
		public var score1Undo:String;
		public var score2Undo:String;
		public var condition1Undo:String;
		public var condition2Undo:String;
		public var selectedCoding:int;
		
		public var customerId:int;
		public var pipeId:int;
		public var projectId:int;
		public var inspectionId:int;
		public var languageId:int;
		public var employeeId:int;
		public var standardId:int;
		public var selectedNum:int;
		public var lastAddedId:int;
		public var imageName:String;
		public var isUpdate:Boolean = false;
		
		public var videoFileListCollection:ArrayCollection;
		public var isVideoUploading:Boolean = false;
		public var videoManagerCurrentState:String = "normal";
		public var videoList:ArrayCollection;
		public var videoPlayerSource:String;
		
		
		private var strClock:Array = [
			{label: '0', data: '0'},
			{label: '1', data: '1'},
			{label: '2', data: '2'},
			{label: '3', data: '3'},
			{label: '4', data: '4'},
			{label: '5', data: '5'},
			{label: '6', data: '6'},
			{label: '7', data: '7'},
			{label: '8', data: '8'},
			{label: '9', data: '9'},
			{label: '10', data: '10'},
			{label: '11', data: '11'},
			{label: '12', data: '12'}];
		
		public var clockPointList:ArrayCollection = new ArrayCollection(strClock);
		
		private static var _instance:CodingModel;
		
		public function CodingModel(){
		}
		
		public static function getInstance():CodingModel {
			if(_instance == null){
				_instance = new CodingModel;
			}
			return _instance;
		}
		
		public function getOpenContinuousList():ArrayCollection {
			var list:ArrayCollection = new ArrayCollection;
			list.removeAll();
			if(codingList){
				for(var i:int = 0; i < codingList.length; i ++){
					var section:String = codingList.getItemAt(i).cont_defect_section;
					var isContinuous:String = codingList.getItemAt(i).cont_defect_yn;
					//trace("section : " + section + "  isContinuous : " + isContinuous);
					if((section && section.charAt(0).toUpperCase() == 'S') && (isContinuous && isContinuous.toUpperCase() != 'N')) {
						list.addItem({distance:codingList.getItemAt(i).distance, open:codingList.getItemAt(i).cont_defect_section, codingId:codingList.getItemAt(i).coding_id});
					}
				}
			}
			return list;
		}
		
		public function getCloseContinuousList():ArrayCollection {
			var list:ArrayCollection = new ArrayCollection;
			list.removeAll();
			if(codingList){
				for(var i:int = 0; i < codingList.length; i++){
					var section:String = codingList.getItemAt(i).cont_defect_section;
					var isContinuous:String = codingList.getItemAt(i).cont_defect_yn;
					//trace("section : " + section + "  isContinuous : " + isContinuous);
					if((section && section.charAt(0).toUpperCase() == 'F') && (isContinuous && isContinuous.toUpperCase() != 'N')) {
						list.addItem({distance:codingList.getItemAt(i).distance, close:codingList.getItemAt(i).cont_defect_section, codingId:codingList.getItemAt(i).coding_id});
					}
				}
			}
			return list;
		}
		
		public function getOpenContinuousNotCloseList():ArrayCollection {
			var listOpen:ArrayCollection = new ArrayCollection;
			var listClose:ArrayCollection = new ArrayCollection;
			var address:Array = new Array();
			listOpen = getOpenContinuousList();
			listClose = getCloseContinuousList();
			
			if(listOpen.length > 0){
				trace("Open length: " + listOpen.length);
				for(var i:int = 0; i < listOpen.length ; i++){
					var numString:String = listOpen.getItemAt(i).open;
					numString = numString.split('S').join("");
					var num:int = int(numString);
					//trace("num : " + num, " i : " + i );
					if(listClose.length > 0) {
						trace("Close length :" + listClose.length);
						for(var j:int = 0; j < listClose.length; j++) {
							var numString2:String = listClose.getItemAt(j).close;
							numString2 = numString2.split('F').join("");
							var num2:int = int(numString2);
							//trace("num2 : " + num2, " j : " + j );
							if(num == num2){
								trace("Got #" + j + " - S:" + i +" F:" + j);
								address.push(i);
								//listOpen.removeItemAt(num);
							}
						}
					}
				}
				
				var offset:int = 0;
				for(var k:int = 0; k < address.length; k ++ ) {
					listOpen.removeItemAt(address[k] - offset);
					offset ++;
				}
			}
			return listOpen;
		}
		
		public function ifRowNum(oItem:Object,iCol:int):String {
			var iIndex:int = videoList.getItemIndex(oItem) + 1;
			return String(iIndex);
		}
		
	}
}